import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from  '@/views/Login.vue'
import Home from '@/views/Home.vue'
import UserList from '@/views/user/UserList.vue'
import RoleList from '@/views/role/RoleList.vue'
import Menus from '@/views/menu/Menus.vue'

import CustomerList from "../views/customer/CustomerList";
import AddCust from "../views/customer/AddCust";
import updateCust from "../views/customer/updateCust";



import LinkMan from "../views/linkman/LinkMan";
import AddLinkMan from "../views/linkman/AddLinkMan";
import upLinkMan from "../views/linkman/upLinkMan";

import Material from '../views/material/Material'
import AddMaterial from '../views/material/AddMaterial'
import UpdateById from '../views/material/UpdateById'
import Detail from '../views/material/Detail'

import Process from '@/views/process/ProcessList.vue'
import UpdateProcess from '@/views/process/UpdateProcess'
import AddProcess from '@/views/process/AddProcess'

import OrdersAdd from "../views/orders/OrdersAdd";
import OrderList from "../views/orders/OrderList";
import OrderProcess from "../views/orders/OrderProcess";

import OrderLog from "../views/orders/OrderLog";

import OrdersDetail from "../views/orders/OrdersDetail";

import Gy from "../views/gy/GyList"

import ProcessWork from "../views/gy/ProcessWork";

import GyDetail from "../views/gy/GyDetail";
import LookDetail from "../views/gy/LookDetail";

import CusLogin from "../views/customer/CusLogin";
import Receipt from "../views/orders/Receipt";
import InvoiceList from "../views/orders/InvoiceList";
import updateReceipt from "../views/orders/updateReceipt";
import CusOrder from "../views/customer/CusOrder";
import InvoiceLog from "../views/customer/InvoiceLog";
import PayReturn from "../views/pay/PayReturn";

import CusHome from "../views/CusHome";


import CusIndex from "../views/CusIndex";

import GyIndex from "../views/orders/GyIndex";
import PayLog from "../views/pay/PayLog";




Vue.use(VueRouter)

const routes = [
  {path:'/',redirect:'/login'},

  {name:'登录',path:'/login',component:Login},
  {name:'客户登录',path:'/cusLogin',component:CusLogin},
  {name:'主页',path:'/home',component:Home,children:[

      {name:'首页',path:'/index',component:CusIndex},
      {name:'首页',path:'/gyIndex',component:GyIndex},



      {name:'首页',path:'/index',component:CusIndex},


      {name:'用户管理',path:'/userList',component:UserList},
      {name:'角色管理',path:'/roleList',component:RoleList},
      {name:'菜单管理',path:'/menus',component:Menus},

      {name:"客户管理",path:'/customerList',component:CustomerList},
      {name:"添加客户",path:"/addCust",component:AddCust},
      {name:"修改客户",path:"/updateCust",component:updateCust},

      {name:'联系人管理',path:'/linkman',component:LinkMan},
      {name:'联系人添加',path:'/addlinkMan',component:AddLinkMan},
      {name:'联系人编辑',path:'/upMan',component:upLinkMan},

      {name:'原材料管理',path:'/material',component:Material},
      {name:'原材料管理',path:'/addMaterial',component:AddMaterial},
      {name:'原材料管理',path:'/updateById',component:UpdateById},
      {name:'原材料管理',path:'/detail',component:Detail},

      {name:'工序管理',path:'/gx',component:Process},
      {name:'工序添加',path:'/addProcess',component:AddProcess},
      {name:'工序编辑',path:'/updateProcess',component:UpdateProcess},


      {name:'订单添加',path:'/ordersAdd',component:OrdersAdd},
      {name:'订单列表',path:'/orderList',component:OrderList},
      {name:'工序编辑',path:'/orderProcess',component:OrderProcess},

      {name:'订单记录',path:'/orderLog',component:OrderLog},

      {name:'订单明细',path:'/ordersDetail',component:OrdersDetail},

      {name:'工艺列表',path:'/gy',component:Gy},

      {name:'工艺添加',path:'/ProcessWork',component:ProcessWork},

      {name:'工艺列表',path:'/gyDetail',component:GyDetail},
      {name:'工艺制作',path:'/lookDetail',component:LookDetail},





    ]
  },
  {name:'主页',path:'/Cushome',component:CusHome,children:[
    {name:'申请发票',path:'/receipt',component:Receipt},
      {name:'修改发票',path:'/updateReceipt',component:updateReceipt},
      {name:'发票列表',path:'/invoiceList',component:InvoiceList},
      {name:'我的订单',path:'/cusOrder',component:CusOrder},
      {name:'成功页面',path:'/payReturn',component:PayReturn},
      {name:'发票日志',path:'/invoiceLog',component:InvoiceLog},
      {name:'支付日志',path:'/payLog',component:PayLog}
    ]}



]

const router = new VueRouter({
  routes
})

router.beforeEach(function (to, from, next) {//to 路由目标 //from  //next 拦截补拦截，拦截到哪 路由守卫

  if(to.path=='/login' || to.path=='/cusLogin'){ //当访问登录组件不拦截
    return next();
  }

  let user=sessionStorage.getItem("user");//获取sessionStorage中用户的信息
  if(user){
    //当前用户已登录
    return next();//继续访问
  }
  let customer = sessionStorage.getItem("customer");
  if(customer){
    return next();
  }
  return  next('/login');
})


export default router
